﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Serialization;
using System.Xml.Linq;


namespace Woodbase.CodeBase.WVR.Objects
{
    [Serializable()]
    [XmlType("movie-rental", Namespace = "http://ns.woodbase.dk/Movies.xsd")]
    public class MovieRental
    {
        [XmlAttribute("rented")]
        public int Rented { get; set; }
        [XmlAttribute("return-date")]
        public DateTime ReturnDate { get; set; }
        [XmlElement("movie")]
        public List<Movie> Movies { get; set;    }
    }

    [Serializable()]
    [XmlType("Movie", Namespace="http://ns.woodbase.dk/Movies.xsd")]
    public class Movie : ISerializable
    {
        [XmlAttribute("title")]
        public string MTitle { get; set; }
        [XmlAttribute("runtime")]
        public int RunTime
        {
            get;
            set; 
        }
        [XmlAttribute("production-year")]
        public int ProductionYear
        {
            get;
            set; 
        }
        [XmlElement("genres")]
        public List<Genre> Genres
        {
            get;
            set; 
        }
        [XmlElement("actors")]
        public List<Actor> Actors
        {
            get;
            set; 
        }
        [XmlAttribute("front-cover")]
        public string CoverFront { get; set; }
        [XmlAttribute("back-cover")]
        public string CoverBack { get; set; }
        [XmlElement("images")]
        public List<string> Images { get; set; }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            
        }

        public XElement ToXml()
        {
            XNamespace ns = XNamespace.Get("http://ns.woodbase.dk/Movies.xsd");

            XElement movie = new XElement(ns + "movie", new XAttribute("title", MTitle), new XAttribute("run-time", RunTime), new XAttribute("year", ProductionYear),
                Genres.Select(x => new XElement(ns+"genre", new XAttribute("name", x.Name))),
                new XElement(ns+"actors", Actors.Select(x=>x.ToXml()))
                );
            return movie;
        }
    }
}